package com.example.administrator.wallet.view.fragment;


import android.support.v4.app.Fragment;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.example.administrator.wallet.R;
import com.example.administrator.wallet.adapter.FindAdapter;
import com.example.administrator.wallet.base.BaseFragment;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;


/**
 * A simple {@link Fragment} subclass.
 */
public class QuotationFragment extends BaseFragment {

    @Bind(R.id.view_title)
    TextView viewTitle;
    @Bind(R.id.mListView)
    ListView mListView;
    @Bind(R.id.smart)
    SmartRefreshLayout smart;
//    @Bind(R.id.loadError)
//    TextView loadError;
//    private List<QuotationListBean.DataBean> datas;
    private FindAdapter adapter;
    private List<String> datas;

    @Override
    public void init() {
        viewTitle.setText(R.string.tab2);
        initData();

        smart.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                initData();
            }
        });
    }

    private void initAdapter() {
        adapter = new FindAdapter(getActivity(), datas);
        mListView.setAdapter(adapter);

//        if(adapter.getCount()>0){
//            loadError.setVisibility(View.GONE);
//        }
    }

    private void initData() {
        datas = new ArrayList<>();
        datas.add(getString(R.string.kkserver));
        datas.add(getString(R.string.applocation));
        initAdapter();
//        datas.clear();
//        IRequestManager manager = RequestFactory.getReqequestManager();
//        Map<String, String> mMap = new HashMap<>();
//        mMap.put("chain_network", Api.network);
//        manager.httpPost(Api.BaseUrl + Api.QuotationList, mMap, new IRequestCallback() {
//            @Override
//            public void onSuccess(String Response) {
//                smart.finishRefresh();
//                Gson mGson = new Gson();
//                QuotationListBean quotationListBean = mGson.fromJson(Response, QuotationListBean.class);
//                datas.addAll(quotationListBean.getData());
//                initAdapter();
////                Toast.makeText(getActivity(), quotationListBean.getMessage(), Toast.LENGTH_SHORT).show();
//            }
//
//            @Override
//            public void onFailure(String error) {
//                Toast.makeText(getActivity(), error, Toast.LENGTH_SHORT).show();
//            }
//        });
    }

    @Override
    public int getLayoutResource() {
        return R.layout.fragment_find;
    }
}
